#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
int sum[N], h[N], tree[N];
int n;
int lowbit(int x)
{
	return x & -x;
}
void add(int x, int v)
{
	for (int i = x; i < N; i += lowbit(i)) {
		tree[i] += v;
	}
}
int query(int x)
{
	int ans = 0;
	for (int i = x; i; i -= lowbit(i)) {
		ans += tree[i];
	}
	return ans;
}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
		h[i]++;
	}
	for (int i = 0; i < n; i++) {
		int y = h[i];
		sum[i] = query(N - 1) - query(y);
		add(y, 1);
	}
	memset(tree, 0, sizeof(tree));
	for (int i = n - 1; i >= 0; i--) {
		int y = h[i];
		sum[i] += query(y - 1);
		add(y, 1);
	}
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		ans += (LL)sum[i] * (sum[i] + 1) / 2;
	}
	cout << ans << endl;
	return 0;
}
